{% extends 'main.html' %}

{% block pid %}id="ptitle_detail"{%endblock%}

{% block content %}
<section class="title_detail">	
	<header>
			<h1>{{ book.title }}</h1> 												
			<p>					
				{{ book.pubdate | date("Y") }}	{{ language }}
			</p>
			<p class="ui-state-error">{{ flash.error }}</p>	
	</header>		
	<div data-role="collapsible">
		<h2>{{page.glob.l10n.download}}</h2>
		{% if protect_dl == true %} 
		<div class="dl_access">
			<p>
				{{ page.glob.l10n.check_access_info }}
			</p>
			<a data-role="button" data-rel="dialog" href="{{page.rot}}/titles/{{book.id}}/showaccess/">
				{{ page.glob.l10n.check_access }}
			</a>
		</div>
		{% endif %}	
		<div class ="dl_download" {% if protect_dl == true %} hidden="true" {% endif %}>
			<p>
				{{ page.glob.l10n.presskey }}
			</p>
			<div data-role="controlgroup" data-type="horizontal" class="downButtons">
				{% for format in formats %}				
						<a data-role="button" 
							{% if page.glob.glob_dl_toggle == true %} disabled="true" {% endif %} 
							data-ajax="false" 
							href="{{page.rot}}/titles/{{book.id}}/file/{{format.name|url_encode()}}.{{format.format|lower}}">
								{{ format.format }} | {{format.uncompressed_size|hfsize}}
						</a>
				{% endfor %}
				{% if kindle_format %}
					<input id="kindleButton" type="button" data-inline="true" data-icon="forward" value="{{page.glob.l10n.send_to_kindle}}" />
				{% endif %}
			</div>
		</div>
	</div>
	{% if kindle_format %}
	    <div data-role="popup" id="kindlePopup" data-overlay-theme="a" data-theme="c" style="max-width:450px;" class="ui-corner-all" data-transition="pop" data-dismissible="false">
	      <div data-role="header" data-theme="a" class="ui-corner-top">
	        <h1>{{page.glob.l10n.send_to_kindle}}</h1>
	      </div>
	      <div data-role="content" data-theme="a" class="ui-corner-bottom ui-content">
	        <h4 class="ui-title">{{ page.glob.l10n.presskey2 }}</h4>
	        <p><em>{{kindle_from_email}}</em> {{ page.glob.l10n.presskey3 }}</p>
			<form action="{{page.rot}}/titles/{{book.id}}/kindle/{{kindle_format.name|url_encode()}}.{{kindle_format.format|lower}}" method="POST" id="ajax-form" data-ajax="false">
			<div style="padding:5px 0 0 5px;max-width:280px;">
				<label for="kindleEmail" class="ui-hidden-accessible">{{page.glob.l10n.kindle_to_email}}</label>
				<input type="email" name="kindleEmail" id="kindleEmail" value="" placeholder="{{page.glob.l10n.kindle_to_email}}" data-theme="d" data-clear-btn="true" />
		  	</div>
	      	<div id="ajax-message" style="height:0.7em;padding-bottom:5px;">
	        	<span id="msg" style="color:red;display:none;"><small>{{ page.glob.l10n.error_kindle_send }}</small></span> 
	      	</div>
	      	<input id="ajax-form-button" type="submit" data-inline="true" data-theme="b" value="{{page.glob.l10n.send_now}}"/>
	      	<a href="#" data-role="button" data-inline="true" data-rel="back" data-theme="c">{{page.glob.l10n.cancel}}</a>  
	        </form> 
		  </div>
		</div>
	{% endif %}
	<aside class="title_detail_image">
		{% if book.has_cover %}		
		<img src="{{page.rot}}/titles/{{ book.id }}/cover/" />
		{% endif %}		
	</aside>
	<section class="title_details">
		<div id="authors" data-role="collapsible" data-collapsed="false">
				<h2>{{page.glob.l10n.authors}}</h2>
				{% for author in authors %}
				<a data-role="button" data-icon="info" href="{{page.rot}}/authors/{{author.id}}/0/">{{ author.name }}</a>
				{% endfor %} 
		</div>
		{% if series != NULL %}
		<div id="series" data-role="collapsible">
				<h2>{{page.glob.l10n.series}}</h2>
				{% for this_series in series %}
				<a data-role="button" data-icon="info" href="{{page.rot}}/series/{{this_series.id}}/0/">{{ this_series.name }} ({{book.series_index}})</a>
				{% endfor %} 
		</div>		
		{% endif %}
		<div id="tags" data-role="collapsible">
			<h2>{{page.glob.l10n.tags}}</h2>			
			<p>
				{% for tag in tags %}
				<a data-role="button" data-mini="true" data-inline="true" href="{{page.rot}}/tags/{{tag.id}}/0/">{{ tag.name }}</a>
				{% endfor %}
			</p>
		</div>
		{% if show_idlinks %}
		<div id="idlinks" data-role="collapsible" data-collapsed="false">
			<h2>{{page.glob.l10n.idlinks}}</h2>			
			<p>
				{% for id in ids %}
					{% if id_templates[id.type] != NULL %}
						<a data-role="button" data-icon="cloud" rel="external" href="{{ id_templates[id.type][0]|replace({'%id%': id.val})}}">{{ id_templates[id.type][1] }}</a>
					{% endif %}
				{% endfor %}
			</p>
		</div>
		{% endif %}
		{% if ccs != NULL %}
		<div id="custom_columns" data-role="collapsible">
			<h4>{{page.glob.l10n.custom_columns}}</h4>			
			<table id="custom_columns_table">
				<tbody>
					{% for cc in ccs %}
					<tr>
						<th>
							{{cc.name}}
						</th>
						<td>
							{% if cc.type == 'comments' %}
								{% autoescape false %}{{cc.value}}{% endautoescape %}
							{% else %}
								{% if cc.type == 'rating' %}
									{% set i = cc.value/2 %}
									{% for y in 1..i %}
										 &#10033;
									{% endfor %}
								{% else %}
									{% if cc.type == 'bool' %}
										{% if cc.value == 1 %}
										 	&#10004;
										{% else %}	 
											 &#10006;
										{% endif %}			 
									{% else %}
										{{cc.value}}
									{% endif %}	
								{% endif %}
							{% endif %}
						</td>
					</tr>
					{% endfor %}
				</tbody>
			</table>
		</div>
		{% endif %}
		{% if comment %}
		<div id="comment">
				<h4>{{page.glob.l10n.comment}}</h4>			
				<div>
					{% autoescape false %}
					{{ comment }}
					{% endautoescape %}
				</div>
		</div>
		{% endif %}
	</section>
</section>


{% endblock %}
